import React, { Component } from 'react'
import { nanoid } from 'nanoid'

export default class Header extends Component {
    handleKeyUp = (event)=>{
        const {keyCode, target} = event
        if(keyCode===13&&target.value.trim()!==''){
            var newTodo = { id: nanoid() ,name: target.value, done: false }
            this.props.addItem(newTodo)
            target.value = ''
        }
    }
    render() {
        return (
            <div>请输入代办事项：<input type="text"  onKeyUp={this.handleKeyUp} placeholder='请输入你的任务名称, 按回车确认'/></div>
        )
    }
}
